<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- 点击按钮 往数组里面新增元素 -->
        <input type="text" v-model="msg">   <button  @click="add">新增</button>  
        <p>数组的长度是 {{arrlen}}</p>
        <div v-for="(item,index) in arr"  :key="index">{{item}}</div>
    </div>

    <script>


        new Vue({
            el: "#app",
            data() {
                return {
                    // 页面刷新从本地读取数据
                    arr: [],
                    msg:""
                }
            },
            methods:{
                add(){
                    this.arr.push(this.msg)
                }
            },
            // 定义计算属性
            computed:{
                arrlen(){
                    return this.arr.length
                }
            }
           
        })

    </script>
</body>

</html>